<template>
  <div>
    <div
      class="left"
      :class="{ 'left-hide': leftHide }"
      ref="leftRef"
    >
      <div class="left-content">
        <div class="left-content-tag-t" />
        <div class="left-content-tag-b" />
        <div class="left-content-title">规划管理</div>
        <div class="left-content-search">
          <Search
            v-model="keyword"
            @input="onSearchChange"
          />
        </div>
        <el-scrollbar class="left-content-tree">
          <Tree
            :filter="keyword"
            :viewerId="viewerId"
            :treeTypeName="treeTypeName"
            @handleCheck="handleCheck"
            @handleNodeClick="handleNodeClick"
            @handleCheckList="getLayerList"
          />
        </el-scrollbar>
      </div>
      <div
        class="left-close"
        @click="leftHide = !leftHide"
      ></div>
      <div
        class="bar"
        @mousedown.prevent="handleLeftMouseDown"
      ></div>
    </div>
    <div
      class="right"
      :class="{ 'right-hide': rightHide }"
      ref="rightRef"
    >
      <el-tabs
        v-model="rightTabActiveName"
        @tab-click="handleRightTabClick"
      >
        <el-tab-pane
          v-if="layerOptions.length > 0"
          label="数据统计"
          name="statistics"
        >
          <el-scrollbar
            v-if="layerOptions.length > 0"
            class="right-content"
          >
            <div class="right-content-title">
              <div class="right-content-title-l"></div>
              <p class="right-content-title-r">数据统计</p>
              <Icon
                title="筛选"
                :name="
                  filterPanelVisible
                    ? 'shaixuanshouqi'
                    : 'shaixuan'
                "
                font-size="20"
                :color="
                  filterPanelVisible
                    ? 'rgba(0, 210, 255, 1)'
                    : '#D2E6F0'
                "
                @click.native="
                  filterPanelVisible = !filterPanelVisible
                "
              />
            </div>
            <transition>
              <el-form
                v-if="filterPanelVisible"
                label-position="top"
              >
                <el-form-item
                  label="统计范围："
                  class="tjfw"
                  v-if="
                    this.activeLayer.areaAgg === 1 ||
                    this.activeLayer.customAgg === 1
                  "
                >
                  <el-cascader
                    v-if="this.activeLayer.areaAgg === 1"
                    v-model="statisticsForm.area"
                    popper-class="my-cascader"
                    :options="areaOptions"
                    :show-all-levels="false"
                    :props="{ checkStrictly: true }"
                    @change="cascaderChange"
                    @expand-change="cascaderExpandChange"
                  />
                  <Icon
                    v-if="this.activeLayer.customAgg === 1"
                    title="绘制"
                    name="zidingyi"
                    font-size="16"
                    style="display: inline-block"
                    color="rgba(0, 210, 255, 1)"
                    @click.native="drawCustomBound"
                  />
                  <span
                    v-if="this.activeLayer.customAgg === 1"
                    class="custom-bound"
                    @click="drawCustomBound"
                    >自定义范围</span
                  >
                </el-form-item>
                <el-form-item label="统计图层：">
                  <el-select
                    :popper-append-to-body="false"
                    v-model="statisticsForm.layer"
                    @change="layerChange"
                  >
                    <el-option
                      v-for="item in layerOptions"
                      :key="item.pkid"
                      :label="item.sourceName"
                      :value="item.pkid"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item
                  label="统计指标："
                  v-if="this.activeLayer.showChart"
                >
                  <el-select
                    :popper-append-to-body="false"
                    v-model="statisticsForm.target"
                    clearable
                  >
                    <el-option
                      v-for="item in targetOptions"
                      :key="item.field"
                      :label="item.caption"
                      :value="item.field"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item
                  label="分类字段："
                  v-if="this.activeLayer.showChart"
                >
                  <el-select
                    :popper-append-to-body="false"
                    v-model="statisticsForm.label"
                    clearable
                  >
                    <el-option
                      v-for="item in labelOptions"
                      :key="item.field"
                      :label="item.caption"
                      :value="item.field"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item
                  label="统计方式："
                  v-if="this.activeLayer.showChart"
                >
                  <el-select
                    :popper-append-to-body="false"
                    v-model="statisticsForm.statistics"
                    clearable
                  >
                    <el-option
                      v-for="item in statisticsOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-form>
            </transition>
            <Chart1
              v-if="dataOption1 && dataOption2"
              class="right-content-echart"
              :chart1-height="chart1Height"
              :chart-data1="dataOption1"
              :chart-data2="dataOption2"
            />
          </el-scrollbar>
        </el-tab-pane>
        <el-tab-pane label="属性" name="properties">
          <div
            class="multi-detail"
            v-if="
              multiDetailData.length > 0 &&
              multiDetailIndex !== -1
            "
          >
            <div class="multi-detail-header">
              <span class="multi-detail-header-left">{{
                multiDetailIndex !== -1
                  ? multiDetailData[multiDetailIndex]
                      .title || ''
                  : ''
              }}</span>
              <div class="multi-detail-header-right">
                <Icon
                  class="icon"
                  :class="
                    multiDetailIndex !== 0
                      ? 'enable'
                      : 'disable'
                  "
                  title="上一个"
                  name="west"
                  font-size="20"
                  :color="
                    multiDetailIndex !== 0
                      ? 'rgba(0, 210, 255, 1)'
                      : '#A7BECA'
                  "
                  @click.native="
                    changeMultiDetailIndex('previous')
                  "
                />
                <Icon
                  class="icon"
                  :class="
                    multiDetailIndex !==
                    multiDetailData.length - 1
                      ? 'enable'
                      : 'disable'
                  "
                  title="下一个"
                  name="east"
                  font-size="20"
                  :color="
                    multiDetailIndex !==
                    multiDetailData.length - 1
                      ? 'rgba(0, 210, 255, 1)'
                      : '#A7BECA'
                  "
                  @click.native="
                    changeMultiDetailIndex('next')
                  "
                />
              </div>
            </div>
            <div class="multi-detail-content">
              <el-scrollbar
                ref="multiDetailScrollBarRef"
                v-if="multiDetailIndex !== -1"
              >
                <div
                  class="multi-detail-content-item"
                  v-for="(value, name) in multiDetailData[
                    multiDetailIndex
                  ].detailData"
                  :key="name"
                >
                  <span class="name"
                    >{{ name || '' }}:
                  </span>
                  <span class="value">{{
                    value || ''
                  }}</span>
                </div>
              </el-scrollbar>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="图例" name="legend">
          <el-scrollbar>
            <el-collapse class="legend-collapse">
              <el-collapse-item
                v-for="item in loadedLayers"
                :title="item.label"
                :name="item.label"
                :key="item.value"
              >
                <div
                  class="legend-list"
                  v-if="legendData[item.value]"
                >
                  <div
                    v-for="legendItem in legendData[
                      item.value
                    ]"
                    :key="legendItem.name"
                    class="legend-list-item"
                  >
                    <el-image
                      :src="legendItem.img"
                      fit="none"
                    />
                    <span>{{ legendItem.name }}</span>
                  </div>
                </div>
              </el-collapse-item>
            </el-collapse>
          </el-scrollbar>
        </el-tab-pane>
      </el-tabs>
      <div
        class="right-close"
        @click="rightHide = !rightHide"
      ></div>
      <div
        class="bar"
        @mousedown.prevent="handleRightMouseDown"
      ></div>
    </div>
  </div>
</template>

<script>
import Icon from '@/components/icon'
import Search from '@/components/search'
import Chart1 from '@/views/cockpit/now/components/chart1'
import Tree from '@/components/tree'
import { statisticsQuery } from '@/api/tree'
import { getAction } from '@/utils/helper'
import axios from 'axios'
import { Loading } from 'element-ui'
import { getAreaData } from '@/api/area'
// import { bounds1, bounds2 } from '@/assets/bounds'

let loadingInstance

let _layerManager

const _mapViewer = {}

let customAreaHandlerPolygon

export default {
  name: 'plan',
  components: {
    Icon,
    Search,
    Chart1,
    Tree
  },
  inject: ['viewerId'],
  data() {
    return {
      leftX: '',
      leftWidth: '',
      rightX: '',
      rightWidth: '',
      filterPanelVisible: true,
      // 当前服务类型
      treeTypeName: '规划',
      // 关键词 前端过滤树形结构
      keyword: '',
      filterKeyword: '',
      // 隐藏侧边
      leftHide: false,
      rightHide: true,
      rightTabActiveName: 'statistics',
      multiDetailData: [],
      multiDetailIndex: -1,
      // 统计数据
      statisticsForm: {
        area: '',
        layer: '',
        target: '',
        label: '',
        statistics: ''
      },
      points: [],
      areaList: [],
      areaOptions: [
        {
          label: '全部',
          value: 'all'
        }
      ],
      layerOptions: [],
      activeLayer: null,
      targetOptions: [],
      labelOptions: [],
      statisticsOptions: [
        {
          label: '平均值',
          value: 'AVG'
        },
        {
          label: '计数',
          value: 'COUNT'
        },
        {
          label: '求和',
          value: 'SUM'
        }
      ],
      chart1Height: 0,
      dataOption1: null,
      dataOption2: null,
      loadedLayers: [],
      selectedLayer: '',
      legendData: {}
    }
  },
  async created() {
    const { viewer, layerManager } = await getAction(
      this.viewerId
    )
    _layerManager = layerManager
    _mapViewer[this.viewerId] = viewer
    this.$bus.$on('togglePanel', (flag) => {
      this.leftHide = flag
    })
    this.$bus.$on(
      'handleDetailData',
      (flag, data, index) => {
        if (flag) {
          this.rightHide = false
          this.multiDetailData = data
          this.multiDetailIndex = index
          this.rightTabActiveName = 'properties'
        } else {
          this.multiDetailData = []
          this.multiDetailIndex = -1
          // this.rightTabActiveName = 'statistics'
        }
      }
    )

    this.$bus.$on('removeAdd', () => {
      this.getLayers(true)
    })
    this.$bus.$on('removeLayer', () => {
      this.getLayers(true)
    })
    this.getLayers()
  },
  computed: {
    defaultViewId() {
      return this.$store.state.layer.defaultViewId
    },
    treeTypeId() {
      return this.$store.state.tree.treeType[
        this.treeTypeName
      ]
    }
  },
  methods: {
    onSearchChange(newValue) {
      this.filterKeyword = newValue
    },
    handleCheck(bool) {
      // this.rightHide = !bool
    },
    cascaderChange(value) {
      const parentAreaCode = value[0]
      const childAreaCode =
        value.length === 2 ? value[1] : null
      const currentAreaCode =
        childAreaCode || parentAreaCode
      this.statisticsForm = Object.assign(
        this.statisticsForm,
        {
          area: currentAreaCode
        }
      )
      console.log('cascaderChange', currentAreaCode)
    },
    cascaderExpandChange(value) {
      const parentAreaCode = value[0]
      const parent = this.areaList.find(
        (item) => item.value === parentAreaCode
      )
      if (
        parentAreaCode !== 'all' &&
        parentAreaCode !== 'custom' &&
        parent &&
        parent.children.length === 0
      ) {
        this.showLoading()
        getAreaData(parentAreaCode)
          .then((res) => {
            this.hideLoading()
            const { data } = res
            if (data) {
              parent.children = data.map((item) => {
                return {
                  label: item.name,
                  value: item.areaCode,
                  region: JSON.parse(item.region)
                }
              })
            }
          })
          .catch((err) => {
            console.error(err)
            this.hideLoading()
          })
      }
    },
    getLayerList(data, currentNode) {
      this.layerOptions = data.filter(
        (item) => item.showChart === 1
      )
      if (currentNode) {
        this.rightHide = currentNode.showChart !== 1
      }
      if (
        this.layerOptions.indexOf(currentNode) === -1 &&
        this.layerOptions.indexOf(this.activeLayer) === -1
      ) {
        this.dataOption1 = null
        this.dataOption2 = null
        this.statisticsForm = {
          area: '',
          layer: '',
          target: '',
          label: '',
          statistics: ''
        }
        this.activeLayer = null
      }
      if (
        !this.activeLayer &&
        this.layerOptions.length > 0
      ) {
        this.layerChange(this.layerOptions[0].pkid, true)
      } else if (this.activeLayer) {
        if (this.layerOptions.indexOf(currentNode) !== -1) {
          this.layerChange(currentNode.pkid, true)
        }
      }
    },
    layerChange(e, append) {
      this.activeLayer = this.layerOptions.find((item) => {
        return item.pkid === e
      })
      if (append) {
        this.statisticsForm.layer = this.activeLayer.pkid
      }
      this.points = []
      this.areaOptions = [
        {
          label: '全部',
          value: 'all'
        }
      ]
      if (this.activeLayer.areaAgg !== 1) {
        this.statisticsForm.area = 'all'
      } else {
        this.statisticsForm.area = ''
      }
      this.statisticsForm.label = ''
      this.statisticsForm.target = ''
      this.statisticsForm.statistics = ''
      this.dataOption1 = null
      this.dataOption2 = null
      if (this.activeLayer.showChart) {
        if (this.activeLayer.areaAgg === 1) {
          if (this.areaList.length === 0) {
            console.log('无行政区划数据，请求')

            this.showLoading()
            getAreaData(1)
              .then((res) => {
                this.hideLoading()
                this.areaList.push(
                  ...res.data.map((item) => {
                    return {
                      label: item.name,
                      value: item.areaCode,
                      region: JSON.parse(item.region),
                      children: []
                    }
                  })
                )
                this.areaOptions.push(...this.areaList)
              })
              .catch((err) => {
                console.error(err)
                this.hideLoading()
              })

            // axios
            //   .get(window.AREA_QUERY_URL + '/layers.json')
            //   .then((res) => {
            //     if (res.data) {
            //       // const layers = res.data[0].subLayers.layers
            //       // this.areaOptions = [
            //       //   {
            //       //     label: '全部',
            //       //     value: 'all'
            //       //   },
            //       //   ...layers.map((layer) => {
            //       //     const name = layer.name.substring(0, layer.name.indexOf('@'))
            //       //     return {
            //       //       label: name,
            //       //       value: name,
            //       //       bounds: layer.bounds
            //       //     }
            //       //   })
            //       // ]
            //
            //       const namesParams = []
            //       res.data[0].subLayers.layers.forEach(
            //         (subLayer) => {
            //           namesParams.push(subLayer.name)
            //         }
            //       )
            //       // console.log('nameParams', namesParams)
            //
            //       // 查询方式1: 手动拼接参数
            //       // axios.post(window.AREA_QUERY_URL + '/queryResults.json?returnContent=true', {
            //       //   queryMode: 'SqlQuery',
            //       //   queryParameters: {
            //       //     customParams: null,
            //       //     prjCoordSys: null,
            //       //     expectCount: 100000,
            //       //     networkType: 'LINE',
            //       //     queryOption: 'ATTRIBUTEANDGEOMETRY',
            //       //     queryParams: namesParams.map((i) => {
            //       //       return {
            //       //         attributeFilter: 'SmID != "0"',
            //       //         name: i
            //       //       }
            //       //     }),
            //       //     startRecord: 0,
            //       //     holdTime: 10,
            //       //     returnCustomResult: false,
            //       //     returnFeatureWithFieldCaption: false
            //       //   }
            //       // }).then((result) => {
            //       //   console.log(result)
            //       //   result.data.recordsets.forEach((recordset) => {
            //       //     recordset.features.forEach((feature) => {
            //       //       let name
            //       //       const layerIndex = feature.fieldNames.indexOf('Layer')
            //       //       const zldwmcIndex = feature.fieldNames.indexOf('ZLDWMC')
            //       //       const xzqmcIndex = feature.fieldNames.indexOf('XZQMC')
            //       //       const smidIndex = feature.fieldNames.indexOf('SmID')
            //       //       const smID = feature.fieldValues[smidIndex]
            //       //       if (layerIndex !== -1) { // 找到Layer
            //       //         name = feature.fieldValues[layerIndex]
            //       //       } else if (zldwmcIndex !== -1) { // 找到坐落单位名称
            //       //         name = feature.fieldValues[zldwmcIndex]
            //       //       } else if (xzqmcIndex !== -1) { // 找到行政区名称
            //       //         name = feature.fieldValues[xzqmcIndex]
            //       //       }
            //       //       if (name && smID) {
            //       //         this.areaList.push({
            //       //           label: name,
            //       //           value: name + '-' + smID,
            //       //           bounds: feature.geometry.points.map((point) => {
            //       //             return [point.y, point.x]
            //       //           })
            //       //         })
            //       //       }
            //       //     })
            //       //   })
            //       //   this.areaOptions = [
            //       //     {
            //       //       label: '全部',
            //       //       value: 'all'
            //       //     },
            //       //     ...this.areaList
            //       //   ]
            //       //   this.hideLoading()
            //       // }).catch((err) => {
            //       //   this.hideLoading()
            //       //   console.error(err)
            //       // })
            //
            //       // 查询方式2: 使用sdk
            //       // const param = new SuperMap.QueryBySQLParameters({
            //       //   queryParams: namesParams.map((namesParam) => {
            //       //     return {
            //       //       attributeFilter: 'SmID != "0"',
            //       //       name: namesParam
            //       //     }
            //       //   })
            //       // })
            //       // L.supermap
            //       //   .queryService(window.AREA_QUERY_URL)
            //       //   .queryBySQL(param, (result) => {
            //       //     console.log('result', result)
            //       //     result.result.recordsets.forEach((recordset) => {
            //       //       const features = recordset.features
            //       //       if (
            //       //         features &&
            //       //         features.features.length > 0
            //       //       ) {
            //       //         console.log('features', features)
            //       //         // features.features.forEach((feature) => {
            //       //         //   const name = feature.properties['TextString']
            //       //         //   if (name.indexOf(this.searchKeyword) !== -1) {
            //       //         //     // console.log('匹配成功', feature)
            //       //         //     this.searchResult.push({
            //       //         //       id: this.generateUUID(),
            //       //         //       name: name,
            //       //         //       address: '',
            //       //         //       geojson: feature
            //       //         //     })
            //       //         //   }
            //       //         // })
            //       //       }
            //       //     })
            //       //   })
            //     }
            //   })
            //   .catch((err) => {
            //     this.hideLoading()
            //     console.error(err)
            //   })
          } else {
            console.log('有行政区划数据，不请求')
            this.areaOptions = [
              {
                label: '全部',
                value: 'all'
              },
              ...this.areaList
            ]
          }
        }
        statisticsQuery({ serviceId: e }).then((res) => {
          if (res.success) {
            this.targetOptions = []
            this.labelOptions = []
            axios
              .get(
                this.activeLayer.dataService +
                  '/fields.json',
                {}
              )
              .then((fieldRes) => {
                const fieldList =
                  fieldRes.data.fieldNames.map(
                    (item, index) => {
                      return {
                        field: item,
                        url: fieldRes.data.childUriList[
                          index
                        ],
                        caption: item
                      }
                    }
                  )
                fieldList.forEach((item) => {
                  axios
                    .get(item.url + '.json')
                    .then((jsonResult) => {
                      item.caption =
                        jsonResult.data.fieldInfo.caption
                    })
                })
                this.targetOptions = fieldList.filter(
                  (field) =>
                    res.data.aggFields.indexOf(
                      field.field
                    ) !== -1
                )
                this.labelOptions = fieldList.filter(
                  (field) =>
                    res.data.groupFields.indexOf(
                      field.field
                    ) !== -1
                )
                if (append) {
                  this.statisticsForm.area = 'all'
                  this.statisticsForm.target =
                    this.targetOptions[0].field
                  this.statisticsForm.label =
                    this.labelOptions[0].field
                }
              })
              .catch(() => {
                this.$message.error('获取字段失败')
              })
            const list = []
            // 重置统计方式选项
            this.statisticsOptions = [
              {
                label: '平均值',
                value: 'AVG'
              },
              {
                label: '计数',
                value: 'COUNT'
              },
              {
                label: '求和',
                value: 'SUM'
              }
            ]
            res.data.types.forEach((item) => {
              list.push(this.statisticsOptions[item])
            })
            this.statisticsOptions = list
            if (append) {
              this.statisticsForm.statistics =
                this.statisticsOptions[0].value
            }
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    handleNodeClick(data, node, el) {
      const ids = _layerManager.layers.map(
        (item) => item.id
      )
      // console.log(data, node, el)
      // if (data.serviceUrl && !this.rightShow) {
      //   this.rightShow = true
      // }
      if (
        data.serviceUrl &&
        this.rightHide &&
        ids.indexOf(data.pkid) !== -1
      ) {
        if (data.showChart === 1) {
          this.rightHide = false
        }
      } else {
        this.rightHide = true
      }
    },
    drawCustomBound() {
      if (!customAreaHandlerPolygon) {
        this.$bus.$emit('customAreaDrawActived', true)
        customAreaHandlerPolygon = new Cesium.DrawHandler(
          _mapViewer[this.viewerId],
          Cesium.DrawMode.Polygon,
          Cesium.ClampMode.Ground
        )
        customAreaHandlerPolygon.activeEvt.addEventListener(
          (isActive) => {
            if (isActive === true) {
              _mapViewer[
                this.viewerId
              ].enableCursorStyle = false
              _mapViewer[
                this.viewerId
              ]._element.style.cursor = ''
            } else {
              _mapViewer[
                this.viewerId
              ].enableCursorStyle = true
            }
          }
        )
        customAreaHandlerPolygon.drawEvt.addEventListener(
          (result) => {
            customAreaHandlerPolygon.polygon.show = true
            customAreaHandlerPolygon.polyline.show = true
            const regions = []
            for (const pt of result.object.positions) {
              const cartographic =
                Cesium.Cartographic.fromCartesian(pt)
              const longitude = Cesium.Math.toDegrees(
                cartographic.longitude
              )
              const latitude = Cesium.Math.toDegrees(
                cartographic.latitude
              )
              regions.push([latitude, longitude])
            }
            if (
              this.areaOptions.every(
                (option) => option.value !== 'custom'
              )
            ) {
              this.areaOptions.push({
                label: '自定义范围',
                value: 'custom'
              })
            }
            if (this.statisticsForm.area !== 'custom') {
              this.statisticsForm.area = 'custom'
            } else {
              this.statisticsForm.area = ''
              this.statisticsForm.area = 'custom'
            }
            this.points = regions
            // console.log('regions', regions)
            this.$bus.$emit('customAreaDrawActived', false)
            customAreaHandlerPolygon.clear()
            customAreaHandlerPolygon.deactivate()
            customAreaHandlerPolygon = null
          }
        )
        customAreaHandlerPolygon.activate()
      } else {
        this.$bus.$emit('customAreaDrawActived', false)
        customAreaHandlerPolygon.clear()
        customAreaHandlerPolygon.deactivate()
        customAreaHandlerPolygon = null
      }
    },
    showLoading() {
      if (!loadingInstance) {
        loadingInstance = Loading.service({
          fullscreen: true
        })
        console.log('show loading')
      }
    },
    hideLoading() {
      if (loadingInstance) {
        this.$nextTick(() => {
          loadingInstance.close()
          loadingInstance = null
          console.log('hide loading')
        })
      }
    },
    handleLeftMouseDown(e) {
      this.leftX = e.clientX
      this.leftWidth = this.$refs.leftRef.offsetWidth
      document.documentElement.addEventListener(
        'mousemove',
        this.leftMove
      )
      document.documentElement.addEventListener(
        'mouseup',
        this.leftEnd
      )
    },
    leftMove(e) {
      let width = this.leftWidth + e.clientX - this.leftX
      width = width >= 500 ? 500 : width < 282 ? 282 : width
      this.$refs.leftRef.style['min-width'] = `${width}px`
      this.$refs.leftRef.style.setProperty(
        '--scroll-width',
        `${-(width - 47 - 1)}px`
      )
    },
    leftEnd(e) {
      document.documentElement.removeEventListener(
        'mousemove',
        this.leftMove
      )
      document.documentElement.removeEventListener(
        'mouseup',
        this.leftEnd
      )
    },
    handleRightMouseDown(e) {
      this.rightX = e.clientX
      this.rightWidth = this.$refs.rightRef.offsetWidth
      document.documentElement.addEventListener(
        'mousemove',
        this.rightMove
      )
      document.documentElement.addEventListener(
        'mouseup',
        this.rightEnd
      )
    },
    rightMove(e) {
      let width =
        this.rightWidth + (this.rightX - e.clientX)
      width = width >= 500 ? 500 : width < 350 ? 350 : width
      this.$refs.rightRef.style['min-width'] = `${width}px`
      this.$refs.rightRef.style.setProperty(
        '--scroll-width',
        `${-(width - 47 - 1)}px`
      )
    },
    rightEnd(e) {
      document.documentElement.removeEventListener(
        'mousemove',
        this.rightMove
      )
      document.documentElement.removeEventListener(
        'mouseup',
        this.rightEnd
      )
    },
    handleRightTabClick(tab) {
      if (tab.label === '图例') {
        console.log('显示图例数据')
      }
    },
    changeMultiDetailIndex(type) {
      if (type === 'previous') {
        if (
          this.multiDetailIndex !== 0 &&
          this.multiDetailIndex !== -1
        ) {
          this.multiDetailIndex -= 1
        }
      } else {
        if (
          this.multiDetailIndex !==
            this.multiDetailData.length - 1 &&
          this.multiDetailIndex !== -1
        ) {
          this.multiDetailIndex += 1
        }
      }
    },
    getLayers(chooseFirst) {
      const layerList = _layerManager.layers
        .reverse()
        .filter((item) => item.type !== 'layer')
      // console.log('图层', layerList)
      this.loadedLayers.splice(0, this.loadedLayers.length)
      this.loadedLayers.push(
        ...layerList.map((item) => {
          return {
            label: item.title,
            value: item.id,
            data: item
          }
        })
      )
      if (chooseFirst) {
        if (this.loadedLayers.length > 0) {
          this.selectedLayer =
            this.loadedLayers[0] &&
            this.loadedLayers[0].value
        } else {
          this.selectedLayer = ''
        }
      } else {
        if (
          this.loadedLayers.every(
            (item) => item.value !== this.selectedLayer
          )
        ) {
          // 已选择的图层被移除
          this.selectedLayer =
            this.loadedLayers[0] &&
            this.loadedLayers[0].value
        }
      }

      this.loadedLayers.forEach((item) => {
        if (
          !this.legendData[item.data.id] ||
          this.legendData[item.data.id].length === 0
        ) {
          this.getLayerLegendData(item.data)
        }
      })
    },
    getLayerLegendData(layer) {
      console.log('layer', layer)
      this.legendData[layer.id] = []
      axios
        .get(layer.serviceUrl + '/layers.json')
        .then((res) => {
          if (res.data) {
            const subLayerNames = []
            const subLayers = []
            res.data[0].subLayers.layers.forEach(
              (subLayer) => {
                if (
                  subLayer.theme &&
                  subLayer.theme.items &&
                  subLayer.theme.items instanceof Array &&
                  subLayer.theme.items.length
                ) {
                  subLayerNames.push(
                    subLayer.name + '@@' + res.data[0].name
                  )
                  subLayers.push(subLayer)
                }
              }
            )
            console.log('subLayerNames', subLayerNames)
            subLayers.forEach((subLayer, subLayerIndex) => {
              subLayer.theme.items.forEach(
                (item, index) => {
                  this.legendData[layer.id].push({
                    name: item.caption,
                    img:
                      layer.serviceUrl +
                      '/layers/' +
                      subLayerNames[subLayerIndex] +
                      `/items/${index}/legend.png?width=30&height=30`
                  })
                }
              )
            })
          }
        })
        .catch((err) => {
          console.error('查询子图层失败', err)
        })
    }
  },
  watch: {
    leftHide: {
      handler(val) {
        if (!val) {
          this.$bus.$emit('hideSearchPanel')
        }
      }
    },
    statisticsForm: {
      handler(val) {
        this.dataOption1 = null
        this.dataOption2 = null
        if (Object.values(val).every((item) => !!item)) {
          // http://chengyu.caupdwest.com:7000/iserver/services/data-KeJiChengShuJuKu/rest/data/datasources/A_%E7%8E%B0%E7%8A%B6%E6%95%B0%E6%8D%AE%E5%BA%93/datasets/%E7%8E%B0%E7%8A%B6_%E5%BB%BA%E8%AE%BE%E7%94%A8%E5%9C%B0_2000"
          const dataService = this.activeLayer.dataService
          const dataServiceUrl =
            dataService.substring(
              0,
              dataService.lastIndexOf('/datasources/')
            ) + '/featureResults.rjson?returnContent=true'
          // console.log('请求地址', dataServiceUrl)
          const dataSourceAndDataSet = dataService
            .substring(
              dataService.lastIndexOf('/datasources/') +
                '/datasources/'.length
            )
            .split('/datasets/')
            .map((item) => decodeURI(item))
          // console.log('数据源:数据集', dataSourceAndDataSet)

          if (val.area === 'all') {
            // 所有范围
            const sqlParameter = {
              datasetNames: [
                `${dataSourceAndDataSet.join(':')}`
              ],
              getFeatureMode: 'SQL',
              queryParameter: {
                fields: [
                  `${val.statistics}(${val.target}) as alias_name`,
                  `${val.label}`
                ],
                groupBy: `${val.label}`
              }
            }
            // console.log(sqlParameter)
            const queryData = JSON.stringify(sqlParameter)
            axios
              .post(dataServiceUrl, queryData)
              .then((res) => {
                // console.log('res.data', res.data)
                if (res.data.featureCount > 0) {
                  // 表1数据
                  const dataList = []
                  const xLabels = []
                  // 表2数据
                  const dataList2 = []
                  for (
                    let i = 0;
                    i < res.data.features.length;
                    i++
                  ) {
                    const dataItem =
                      res.data.features[i].fieldValues[0]
                    try {
                      const temp =
                        Number.parseFloat(dataItem)
                      dataList.push(temp.toFixed(2))
                      dataList2.push({
                        value: temp.toFixed(2),
                        name: res.data.features[i]
                          .fieldValues[1]
                      })
                    } catch (e) {
                      dataList.push(dataItem)
                      dataList2.push({
                        value: dataItem,
                        name: res.data.features[i]
                          .fieldValues[1]
                      })
                    }
                    xLabels.push(
                      res.data.features[i].fieldValues[1]
                    )
                  }
                  this.chart1Height =
                    xLabels.length * 20 +
                    (xLabels.length - 1) * 20 +
                    20 +
                    20
                  this.dataOption1 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    // dataZoom:
                    //   dataList.length > 10
                    //     ? [
                    //         {
                    //           type: 'inside'
                    //         },
                    //         {
                    //           type: 'slider'
                    //         }
                    //       ]
                    //     : null,
                    yAxis: {
                      type: 'category',
                      data: xLabels,
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLabel: {
                        show: true,
                        interval: 0,
                        // rotate: 40,
                        textStyle: {
                          color: '#fff',
                          fontSize: 12
                        }
                      }
                    },
                    grid: {
                      left: '0%',
                      right: '1%',
                      top: '20',
                      bottom: '20',
                      containLabel: true
                    },
                    xAxis: {
                      type: 'value',
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLine: {
                        show: false,
                        lineStyle: {
                          color: '#fff'
                        }
                      },
                      axisLabel: {
                        show: false
                      },
                      splitLine: {
                        lineStyle: {
                          color: '#ffffff33'
                        }
                      }
                    },
                    series: [
                      {
                        data: dataList,
                        type: 'bar',
                        showBackground: true,
                        barWidth: '20',
                        barGap: '100%',
                        itemStyle: {
                          normal: {
                            color: '#00C8FF',
                            label: {
                              show: true,
                              position: 'top',
                              formatter: function (item) {
                                return item.data
                              },
                              textStyle: {
                                fontSize: 12,
                                color: '#ffffff'
                              }
                            }
                          }
                        },
                        backgroundStyle: {
                          color: 'rgba(255, 255, 255, 0.1)'
                        }
                      }
                    ]
                  }
                  this.dataOption2 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    legend: {
                      show: false,
                      orient: 'vertical',
                      top: 10,
                      bottom: 10,
                      right: 10,
                      itemWidth: 7,
                      itemHeight: 7,
                      textStyle: {
                        color: '#fff'
                      },
                      itemStyle: {
                        borderType: 'solid'
                      },
                      type: 'scroll'
                    },
                    series: [
                      {
                        type: 'pie',
                        radius: ['20%', '50%'],
                        animation: false,
                        label: {
                          show: true,
                          color: '#fff',
                          position: 'top',
                          formatter: function (item) {
                            return item.value
                          }
                        },
                        tooltip: {
                          trigger: 'item',
                          formatter: '{b}: {d}%',
                          position: function (
                            point,
                            params,
                            dom,
                            rect,
                            size
                          ) {
                            //  size为当前窗口大小
                            if (
                              size.viewSize[0] / 2 >=
                              point[0]
                            ) {
                              // 其中point为当前鼠标的位置,在左侧
                              return {
                                right: point[0],
                                top: point[1]
                              }
                            } else {
                              // 其中point为当前鼠标的位置
                              return {
                                right:
                                  point[0] -
                                  size.viewSize[0] / 2,
                                top: point[1]
                              }
                            }
                          }
                        },
                        emphasis: {
                          itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor:
                              'rgba(0, 0, 0, 0.5)'
                          }
                        },
                        labelLine: {
                          show: true
                        },
                        data: dataList2
                      }
                    ]
                  }
                }
              })
              .catch((err) => {
                console.error(err)
              })
          } else if (val.area === 'custom') {
            // 自定义范围
            const polygon = L.polygon([
              ...this.points,
              this.points[0]
            ])
            // 有范围，几何查询
            const param =
              new SuperMap.GetFeaturesByGeometryParameters({
                datasetNames: [
                  `${dataSourceAndDataSet.join(':')}`
                ],
                geometry: polygon,
                spatialQueryMode:
                  SuperMap.SpatialQueryMode.CONTAIN,
                fromIndex: 0,
                toIndex: 10000,
                fields: [
                  `${val.statistics}(${val.target}) as result`,
                  `${val.label}`
                ],
                groupBy: `${val.label}`
              })
            L.supermap
              .featureService(
                dataService.substring(
                  0,
                  dataService.lastIndexOf('/datasources/')
                )
              )
              .getFeaturesByGeometry(param, (result) => {
                // console.log('LeafletFeature result', result)
                // console.log(result.result.features.features)
                if (result.error) {
                  this.$message.error(
                    result.error.errorMsg || '范围查询失败'
                  )
                }
                if (result.result.featureCount > 0) {
                  // 表1数据
                  const dataList = []
                  const xLabels = []
                  // 表2数据
                  const dataList2 = []
                  for (
                    let i = 0;
                    i <
                    result.result.features.features.length;
                    i++
                  ) {
                    const dataItem =
                      result.result.features.features[i]
                        .properties['result']
                    try {
                      const temp =
                        Number.parseFloat(dataItem)
                      dataList.push(temp.toFixed(2))
                      dataList2.push({
                        value: temp.toFixed(2),
                        name: result.result.features
                          .features[i].properties[
                          `${val.label}`
                        ]
                      })
                    } catch (e) {
                      dataList.push(dataItem)
                      dataList2.push({
                        value: dataItem,
                        name: result.result.features
                          .features[i].properties[
                          `${val.label}`
                        ]
                      })
                    }
                    xLabels.push(
                      result.result.features.features[i]
                        .properties[`${val.label}`]
                    )
                  }
                  // console.log('dataList', dataList)
                  // console.log('xLabels', xLabels)
                  // console.log('dataList2', dataList2)
                  this.chart1Height =
                    xLabels.length * 20 +
                    (xLabels.length - 1) * 20 +
                    20 +
                    20
                  this.dataOption1 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    // dataZoom:
                    //   dataList.length > 10
                    //     ? [
                    //         {
                    //           type: 'inside'
                    //         },
                    //         {
                    //           type: 'slider'
                    //         }
                    //       ]
                    //     : null,
                    yAxis: {
                      type: 'category',
                      data: xLabels,
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLabel: {
                        show: true,
                        interval: 0,
                        // rotate: 40,
                        textStyle: {
                          color: '#fff',
                          fontSize: 12
                        }
                      }
                    },
                    grid: {
                      left: '0%',
                      right: '1%',
                      top: '20',
                      bottom: '20',
                      containLabel: true
                    },
                    xAxis: {
                      type: 'value',
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLine: {
                        show: false,
                        lineStyle: {
                          color: '#fff'
                        }
                      },
                      axisLabel: {
                        show: false
                      },
                      splitLine: {
                        lineStyle: {
                          color: '#ffffff33'
                        }
                      }
                    },
                    series: [
                      {
                        data: dataList,
                        type: 'bar',
                        showBackground: true,
                        barWidth: '20',
                        barGap: '100%',
                        itemStyle: {
                          normal: {
                            color: '#00C8FF',
                            label: {
                              show: true,
                              position: 'top',
                              formatter: function (item) {
                                return item.data
                              },
                              textStyle: {
                                fontSize: 12,
                                color: '#ffffff'
                              }
                            }
                          }
                        },
                        backgroundStyle: {
                          color: 'rgba(255, 255, 255, 0.1)'
                        }
                      }
                    ]
                  }
                  this.dataOption2 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    legend: {
                      show: false,
                      orient: 'vertical',
                      top: 10,
                      bottom: 10,
                      right: 10,
                      itemWidth: 7,
                      itemHeight: 7,
                      textStyle: {
                        color: '#fff'
                      },
                      itemStyle: {
                        borderType: 'solid'
                      },
                      type: 'scroll'
                    },
                    series: [
                      {
                        type: 'pie',
                        radius: ['20%', '50%'],
                        animation: false,
                        label: {
                          show: true,
                          color: '#fff',
                          position: 'top',
                          formatter: function (item) {
                            return item.value
                          }
                        },
                        tooltip: {
                          trigger: 'item',
                          formatter: '{b}: {d}%',
                          position: function (
                            point,
                            params,
                            dom,
                            rect,
                            size
                          ) {
                            //  size为当前窗口大小
                            if (
                              size.viewSize[0] / 2 >=
                              point[0]
                            ) {
                              // 其中point为当前鼠标的位置,在左侧
                              return {
                                right: point[0],
                                top: point[1]
                              }
                            } else {
                              // 其中point为当前鼠标的位置
                              return {
                                right:
                                  point[0] -
                                  size.viewSize[0] / 2,
                                top: point[1]
                              }
                            }
                          }
                        },
                        emphasis: {
                          itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor:
                              'rgba(0, 0, 0, 0.5)'
                          }
                        },
                        labelLine: {
                          show: true
                        },
                        data: dataList2
                      }
                    ]
                  }
                }
              })
          } else {
            // 选择区域范围
            // 行政区划范围查询
            // const bounds = bounds2.map((item) => {
            //   return [item[1], item[0]]
            // })
            // const polygon = L.polygon([...bounds])
            let polygon
            const parent = this.areaOptions.find(
              (item) => item.value === val.area
            )
            if (parent) {
              polygon = L.polygon([...parent.region])
            } else {
              try {
                this.areaOptions.forEach((parent) => {
                  if (parent.children) {
                    const child = parent.children.find(
                      (childItem) =>
                        childItem.value === val.area
                    )
                    if (child) {
                      polygon = L.polygon([...child.region])
                      throw new Error('找到item，跳出循环')
                    }
                  }
                })
              } catch (e) {
                console.log(e)
              }
            }
            // const bounds = this.areaOptions.find((option) => option.label === val.area).bounds
            // const polygon = L.polygon([...bounds])
            // 有范围，几何查询
            const param =
              new SuperMap.GetFeaturesByGeometryParameters({
                datasetNames: [
                  `${dataSourceAndDataSet.join(':')}`
                ],
                geometry: polygon,
                spatialQueryMode:
                  SuperMap.SpatialQueryMode.CONTAIN,
                fromIndex: 0,
                toIndex: 10000,
                fields: [
                  `${val.statistics}(${val.target}) as result`,
                  `${val.label}`
                ],
                groupBy: `${val.label}`
              })
            L.supermap
              .featureService(
                dataService.substring(
                  0,
                  dataService.lastIndexOf('/datasources/')
                )
              )
              .getFeaturesByGeometry(param, (result) => {
                // console.log('LeafletFeature result', result)
                // console.log(result.result.features.features)
                if (result.error) {
                  this.$message.error(
                    result.error.errorMsg || '范围查询失败'
                  )
                }
                if (result.result.featureCount > 0) {
                  // 表1数据
                  const dataList = []
                  const xLabels = []
                  // 表2数据
                  const dataList2 = []
                  for (
                    let i = 0;
                    i <
                    result.result.features.features.length;
                    i++
                  ) {
                    const dataItem =
                      result.result.features.features[i]
                        .properties['result']
                    try {
                      const temp =
                        Number.parseFloat(dataItem)
                      dataList.push(temp.toFixed(2))
                      dataList2.push({
                        value: temp.toFixed(2),
                        name: result.result.features
                          .features[i].properties[
                          `${val.label}`
                        ]
                      })
                    } catch (e) {
                      dataList.push(dataItem)
                      dataList2.push({
                        value: dataItem,
                        name: result.result.features
                          .features[i].properties[
                          `${val.label}`
                        ]
                      })
                    }
                    xLabels.push(
                      result.result.features.features[i]
                        .properties[`${val.label}`]
                    )
                  }
                  // console.log('dataList', dataList)
                  // console.log('xLabels', xLabels)
                  // console.log('dataList2', dataList2)
                  this.chart1Height =
                    xLabels.length * 20 +
                    (xLabels.length - 1) * 20 +
                    20 +
                    20
                  this.dataOption1 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    // dataZoom:
                    //   dataList.length > 10
                    //     ? [
                    //         {
                    //           type: 'inside'
                    //         },
                    //         {
                    //           type: 'slider'
                    //         }
                    //       ]
                    //     : null,
                    yAxis: {
                      type: 'category',
                      data: xLabels,
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLabel: {
                        show: true,
                        interval: 0,
                        // rotate: 40,
                        textStyle: {
                          color: '#fff',
                          fontSize: 12
                        }
                      }
                    },
                    grid: {
                      left: '0%',
                      right: '1%',
                      top: '20',
                      bottom: '50',
                      containLabel: true
                    },
                    xAxis: {
                      type: 'value',
                      axisTick: {
                        show: false
                        // 去除刻度
                      },
                      axisLine: {
                        show: false,
                        lineStyle: {
                          color: '#fff'
                        }
                      },
                      axisLabel: {
                        show: false
                      },
                      splitLine: {
                        lineStyle: {
                          color: '#ffffff33'
                        }
                      }
                    },
                    series: [
                      {
                        data: dataList,
                        type: 'bar',
                        showBackground: true,
                        barWidth: '20',
                        barGap: '100%',
                        itemStyle: {
                          normal: {
                            color: '#00C8FF',
                            label: {
                              show: true,
                              position: 'top',
                              formatter: function (item) {
                                return item.data
                              },
                              textStyle: {
                                fontSize: 12,
                                color: '#ffffff'
                              }
                            }
                          }
                        },
                        backgroundStyle: {
                          color: 'rgba(255, 255, 255, 0.1)'
                        }
                      }
                    ]
                  }
                  this.dataOption2 = {
                    tooltip: {
                      trigger: 'item',
                      position: function (
                        point,
                        params,
                        dom,
                        rect,
                        size
                      ) {
                        //  size为当前窗口大小
                        if (
                          size.viewSize[0] / 2 >=
                          point[0]
                        ) {
                          // 其中point为当前鼠标的位置,在左侧
                          return {
                            right: point[0],
                            top: point[1]
                          }
                        } else {
                          // 其中point为当前鼠标的位置
                          return {
                            right:
                              point[0] -
                              size.viewSize[0] / 2,
                            top: point[1]
                          }
                        }
                      }
                    },
                    legend: {
                      show: false,
                      orient: 'vertical',
                      top: 10,
                      bottom: 10,
                      right: 10,
                      itemWidth: 7,
                      itemHeight: 7,
                      textStyle: {
                        color: '#fff'
                      },
                      itemStyle: {
                        borderType: 'solid'
                      },
                      type: 'scroll'
                    },
                    series: [
                      {
                        type: 'pie',
                        radius: ['20%', '50%'],
                        animation: false,
                        label: {
                          show: true,
                          color: '#fff',
                          position: 'top',
                          formatter: function (item) {
                            return item.value
                          }
                        },
                        tooltip: {
                          trigger: 'item',
                          formatter: '{b}: {d}%',
                          position: function (
                            point,
                            params,
                            dom,
                            rect,
                            size
                          ) {
                            //  size为当前窗口大小
                            if (
                              size.viewSize[0] / 2 >=
                              point[0]
                            ) {
                              // 其中point为当前鼠标的位置,在左侧
                              return {
                                right: point[0],
                                top: point[1]
                              }
                            } else {
                              // 其中point为当前鼠标的位置
                              return {
                                right:
                                  point[0] -
                                  size.viewSize[0] / 2,
                                top: point[1]
                              }
                            }
                          }
                        },
                        emphasis: {
                          itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor:
                              'rgba(0, 0, 0, 0.5)'
                          }
                        },
                        labelLine: {
                          show: true
                        },
                        data: dataList2
                      }
                    ]
                  }
                }
              })
          }
        }
      },
      deep: true
    },
    layerOptions: {
      handler(val) {
        if (
          !val ||
          val.length === 0 ||
          val.every((item) => item.showChart === 0)
        ) {
          this.rightHide = true
        }
      }
    }
    // selectedLayer: {
    //   handler(val, oldVal) {
    //     if (val) {
    //       const find = this.loadedLayers.find(
    //         (item) => item.value === this.selectedLayer
    //       )
    //       if (find) {
    //         this.getLayerLegendData(find.data)
    //       }
    //     } else {
    //       console.log('clear legend')
    //       if (oldVal) {
    //         this.legendData[oldVal] = []
    //       }
    //     }
    //   }
    // },
  }
}
</script>

<style lang="scss" scoped>
.left {
  position: fixed;
  left: 48px;
  top: 60px;
  width: 282px;
  height: calc(100% - 60px);
  padding: 10px 0;
  background: linear-gradient(
    90deg,
    rgba(25, 47, 61, 0.85),
    rgba(25, 47, 61, 0.1)
  );
  transition: all 1s;
  --scroll-width: -234px;

  &-content {
    width: 100%;
    overflow-x: hidden;
    height: 100%;
    position: relative;

    &-tag {
      &-t {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 5px;

        &::before,
        &::after {
          content: '';
          width: 0;
          height: 0;
          position: absolute;
          top: 0;
        }

        &::before {
          left: 0;
          border-top: 4px solid #fff;
          border-right: 4px solid transparent;
        }

        &::after {
          right: 0;
          border-top: 4px solid #fff;
          border-left: 4px solid transparent;
        }
      }

      &-b {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 5px;

        &::before,
        &::after {
          content: '';
          width: 0;
          height: 0;
          position: absolute;
          bottom: 0;
        }

        &::before {
          left: 0;
          border-bottom: 4px solid #fff;
          border-right: 4px solid transparent;
        }

        &::after {
          right: 0;
          border-bottom: 4px solid #fff;
          border-left: 4px solid transparent;
        }
      }
    }

    &-title {
      height: 50px;
      line-height: 50px;
      padding-left: 14px;
      font-size: 18px;
      font-weight: 800;
      color: #00d2ff;
      word-break: keep-all;
      border-top: 1px solid rgba(255, 255, 255, 0.2);
      border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }

    &-search {
      height: 30px;
      width: calc(100% - 16px);
      margin: 10px auto;
    }

    &-tree {
      border-bottom: 1px solid rgba(255, 255, 255, 0.2);
      margin: 0 8px;
      height: calc(100% - 50px - 50px);

      ::v-deep {
        // tree 背景色
        .el-tree {
          background-color: transparent;
        }

        // 节点选中颜色
        .el-tree-node:focus > .el-tree-node__content {
          background-color: rgba(255, 255, 255, 0.4);
        }

        // 节点样式
        .el-tree-node__content {
          position: relative;
          padding: 4px 0;
          box-sizing: content-box;
          height: auto;
          // 节点hover
          &:hover {
            background-color: rgba(255, 255, 255, 0.4);
          }

          // checkbox移动到右边
          // & > label.el-checkbox {
          //   //position: absolute;
          //   //right: 0;
          // }
        }

        .el-tree-node__expand-icon {
          font-size: 10px;
        }

        // checkbox样式
        .el-checkbox__inner {
          width: 12px;
          height: 12px;
          border: 1px solid rgba(255, 255, 255, 0.7);
          background: rgba(255, 255, 255, 0.3);
        }

        // 节点文字
        .el-tree-node__label {
          font-size: 14px;
          font-weight: 800;
          color: #ffffff;
          padding-right: 40px;
          white-space: normal;
          max-width: 200px;
        }

        // 二级节点文字
        .el-tree-node__children .el-tree-node__label {
          font-weight: 500;
          color: #d2e6f0;
        }

        // scrollbar横向滚动条
        .el-scrollbar__wrap {
          overflow-x: hidden;
        }
      }
    }
  }

  &-hide {
    //width: 0;
    left: var(--scroll-width);

    & > .left-close {
      background-color: red;

      &::before,
      &::after {
        transform-origin: 6px 1px;
      }
    }
  }

  &-close {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 44px;
    cursor: pointer;
    background: #192f3d;
    opacity: 0.7;

    &::before,
    &::after {
      content: '';
      position: absolute;
      width: 7px;
      height: 2px;
      background: #fff;
      top: 50%;
      left: 50%;
      transform-origin: 1px 1px;
    }

    &::before {
      transform: translateX(-50%) translateY(-50%)
        rotateZ(-45deg);
    }

    &::after {
      transform: translateX(-50%) translateY(-50%)
        rotateZ(45deg);
    }
  }

  .bar {
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    cursor: col-resize;
  }
}

.right {
  position: fixed;
  right: 48px;
  top: 60px;
  width: 350px;
  height: calc(100% - 60px);
  background: linear-gradient(
    90deg,
    rgba(25, 47, 61, 0.1),
    rgba(25, 47, 61, 0.85)
  );
  transition: all 1s;
  --scroll-width: -302px;

  .el-tabs {
    height: 100%;
    margin: 0 16px;
    display: flex;
    flex-direction: column;

    ::v-deep {
      .el-tabs__header {
        margin: 0;
      }

      .el-tabs__item {
        color: white;
      }

      .el-tabs__item.is-active {
        color: #00d2ff;
      }

      .el-tabs__item:hover {
        color: #00d2ff;
      }

      .el-tabs__content {
        flex: 1;

        .el-tab-pane {
          height: 100%;
        }
      }

      .multi-detail {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;

        &-header {
          width: 100%;
          height: 43px;
          padding: 16px 6px 16px 16px;
          display: flex;
          justify-content: space-between;
          align-items: center;

          &-left {
            font-size: 16px;
            font-weight: 800;
          }

          &-right {
            display: flex;
            align-items: center;

            .icon {
              &.enable {
                cursor: pointer;
              }
              &.disable {
                cursor: not-allowed;
              }
              ::v-deep {
                .svg-icon {
                  cursor: inherit;
                }
              }
            }

            &-close {
              padding: 10px;
              font-size: 18px;
              cursor: pointer;
            }
          }
        }

        &-content {
          flex: 1;
          overflow: hidden;
          padding: 16px;

          .el-scrollbar {
            height: 100%;
          }

          ::v-deep {
            .el-scrollbar__wrap {
              overflow-x: hidden;

              .el-scrollbar__view {
                height: 100%;
              }
            }
          }

          &-item {
            display: flex;
            align-items: flex-start;

            .name {
              font-size: 14px;
              font-weight: 500;
              color: #d2e6f0;
              min-width: 100px;
              max-width: 100px;
              width: 100px;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }

            .value {
              flex: 1;
              font-size: 14px;
              font-weight: 400;
              color: #ffffff;
              margin-left: 8px;
            }
          }
        }
      }

      .legend-collapse {
        background-color: transparent;
        border-top: none;
        border-bottom: none;

        .el-collapse-item {
          background-color: transparent;

          .el-collapse-item__header {
            background-color: transparent;
            color: white;
            border-bottom: none;
          }

          .el-collapse-item__wrap {
            background-color: transparent;
            border-bottom: none;

            .el-collapse-item__content {
              padding-bottom: 0;
            }
          }
        }
      }

      .legend-list {
        display: flex;
        flex-direction: column;

        &-item {
          display: flex;
          align-items: center;

          &:not(:last-of-type) {
            margin-bottom: 15px;
          }

          .el-image {
            width: 20px;
            height: 20px;
            margin-right: 6px;
          }

          span {
            font-size: 14px;
            color: #d2e6f0;
          }
        }
      }
    }
  }

  ::v-deep {
    // scrollbar横向滚动条
    .el-scrollbar__wrap {
      overflow-x: hidden;

      .tjfw {
        .el-input__inner {
          width: 160px !important;
        }

        .custom-bound {
          color: rgba(0, 210, 255, 1);
          cursor: pointer;
        }
      }

      .el-form {
        background-image: url('../../../../public/img/basemaps/yxjz.png');
        padding-left: 10px;
        background-size: cover;
        background-repeat: no-repeat;
        padding-bottom: 1px !important;
        padding-top: 8px;

        .el-select-dropdown {
          border-color: #4a80a3;

          .el-select-dropdown__empty {
            background-color: #4a80a3;
            color: white;
          }

          .el-select-dropdown__list {
            background-color: #4a80a3;

            .el-select-dropdown__item {
              color: white;
              background-color: #4a80a3;

              &.selected {
                color: white;
              }

              &.hover {
                background-color: #28516c;
              }
            }
          }

          .popper__arrow {
            border-bottom-color: #4a80a3;

            &::after {
              border-bottom-color: #4a80a3;
            }
          }
        }
      }

      .el-form-item {
        margin-bottom: 7px !important;
      }

      .el-form-item__label {
        padding: 0 !important;
        color: white !important;
        line-height: 20px !important;
      }

      .el-input__inner {
        background: rgba(65, 89, 117, 0.5) !important;
        border-color: #4a627f !important;
        height: 30px !important;
        color: #a7beca !important;
      }
    }
  }

  &-content {
    // width: calc(100% - 32px);
    width: 100%;
    height: 100%;
    margin: 20px auto;

    &-title:not(:first-child) {
      padding-top: 26px;
      border-top: 1px solid rgba(255, 255, 255, 0.2);
    }

    &-title {
      padding-bottom: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      //margin-bottom: 11px;

      &-l {
        width: 4px;
        height: 12px;
        background: linear-gradient(0deg, #bcf8ff, #40ebff);
        border-radius: 0 0 0 0;
        margin-right: 10px;
      }

      &-r {
        flex: 1;
        word-break: keep-all;
        font-size: 14px;
        font-weight: 800;
        background: linear-gradient(
          0deg,
          #bcf8ff 0%,
          #40ebff 100%
        );
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }

    &-echart {
      width: 100%;
      //padding: 10px 0;
    }

    &-query {
      display: flex;
      align-items: center;
      justify-content: space-between;

      & span {
        word-break: keep-all;
        font-size: 14px;
        font-weight: 400;
        color: #ffffff;
      }

      //-draw {
      //  display: flex;
      //  align-items: center;
      //
      //  & span {
      //    cursor: pointer;
      //    margin-left: 4px;
      //  }
      //}

      ::v-deep {
        .el-input__inner {
          width: 110px;
          background-color: transparent;
          border: 1px solid rgba(255, 255, 255, 0.4);
          border-radius: 0;
          height: 30px;
          line-height: 30px;
        }

        .el-input__icon {
          line-height: 30px;
        }
      }
    }

    ::v-deep {
      .el-form {
        padding: 10px;

        &-item {
          margin-bottom: 10px;

          &__label {
            color: white;
            padding: 0;
            line-height: 16px;
          }

          &__content {
            .el-input {
              &__inner {
                color: white;
                background: rgba(255, 255, 255, 0.2);
                border: 1px solid rgba(255, 255, 255, 0.2);
              }
            }

            .el-select {
              width: 100%;
            }
          }
        }
      }
    }
  }

  &-hide {
    right: var(--scroll-width);

    & > .right-close {
      background-color: red;

      &::before,
      &::after {
        transform-origin: 1px 1px;
      }
    }
  }

  &-close {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 44px;
    cursor: pointer;
    background: #192f3d;
    opacity: 0.7;

    &::before,
    &::after {
      content: '';
      position: absolute;
      width: 7px;
      height: 2px;
      background: #fff;
      top: 50%;
      left: 50%;
      transform-origin: 6px 1px;
    }

    &::before {
      transform: translateX(-50%) translateY(-50%)
        rotateZ(-45deg);
    }

    &::after {
      transform: translateX(-50%) translateY(-50%)
        rotateZ(45deg);
    }
  }

  .bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    cursor: col-resize;
  }
}
</style>
